package cn.cjj.gulimall.order.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import cn.cjj.gulimall.order.entity.OrderEntity;
import cn.cjj.gulimall.order.service.OrderService;
import cn.cjj.common.utils.PageUtils;
import cn.cjj.common.utils.R;



/**
 * 订单
 *
 * @author cjj
 * @email cjj@gmail.com
 * @date 2021-05-28 10:58:53
 */
@RefreshScope
@RestController
@RequestMapping("order/order")
public class OrderController {
    @Autowired
    private OrderService orderService;


    /**
     * 订单状态【0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭；5->无效订单】
     * @param orderSn
     * @return
     */
    @RequestMapping("/status/{orderSn}")
    public int getOrderStatus(@PathVariable("orderSn") String orderSn) {
        int status = orderService.getOrderStatus(orderSn);

        return status;
    }


    @Value("${module.name}")
    private String moduleName;

    @RequestMapping("/module/name")
    public R getModuleName() {
        return R.ok().put("moduleName", moduleName);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		OrderEntity order = orderService.getById(id);

        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OrderEntity order){
		orderService.save(order);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OrderEntity order){
		orderService.updateById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		orderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
